/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipse.iota.model;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.iota.IotaPackage;

/**
 * @see org.eclipse.iota.IotaPackage#getBinaryOperation()
 * @model kind="class" abstract="true"
 * @generated
 */
public abstract class BinaryOperation extends EObjectImpl implements Operation {
	
	/**
	 * Alternative constructor.
	 * @param e1 Left-hand side of the operation.
	 * @param e2 Right-hand side.
	 */
	public BinaryOperation(Expression e1, Expression e2) {
		super();
		setLeft(e1);
		setRight(e2);
	}
	
	/**
	 * Get the equation that owns this expression.
	 * @generated NOT
	 */
	public Equation basicGetEquation() {
		if (eContainer() instanceof Equation) return (Equation) eContainer();
		if (eContainer() instanceof Expression) return ((Expression) eContainer()).getEquation();
		return null;
	}
		
	/* ---------------------------------------------------------------- *
	 * GENERATED CODE.                                                  *
	 * Do not edit below this line. If you need to edit, move it above  *
	 * this line and change the '@generated'-tag to '@generated NOT'.   *
	 * ---------------------------------------------------------------- */	

	/**
	 * The cached value of the '{@link #getLeft() <em>Left</em>}' containment reference.
	 * @see #getLeft()
	 * @generated
	 * @ordered
	 */
	protected Expression left;

	/**
	 * The cached value of the '{@link #getRight() <em>Right</em>}' containment reference.
	 * @see #getRight()
	 * @generated
	 * @ordered
	 */
	protected Expression right;

	/**
	 * @generated
	 */
	public BinaryOperation() {
		super();
	}

	/**
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return IotaPackage.Literals.BINARY_OPERATION;
	}

	/**
	 * Returns the value of the '<em><b>Equation</b></em>' reference.
	 * @return the value of the '<em>Equation</em>' reference.
	 * @see org.eclipse.iota.IotaPackage#getExpression_Equation()
	 * @model transient="true" changeable="false" volatile="true" derived="true"
	 * @generated
	 */
	public Equation getEquation() {
		Equation equation = basicGetEquation();
		return equation != null && equation.eIsProxy() ? (Equation)eResolveProxy((InternalEObject)equation) : equation;
	}

	/**
	 * Returns the value of the '<em><b>Left</b></em>' containment reference.
	 * @return the value of the '<em>Left</em>' containment reference.
	 * @see #setLeft(Expression)
	 * @see org.eclipse.iota.IotaPackage#getBinaryOperation_Left()
	 * @model containment="true"
	 * @generated
	 */
	public Expression getLeft() {
		return left;
	}

	/**
	 * @generated
	 */
	public NotificationChain basicSetLeft(Expression newLeft, NotificationChain msgs) {
		Expression oldLeft = left;
		left = newLeft;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, IotaPackage.BINARY_OPERATION__LEFT, oldLeft, newLeft);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * Sets the value of the '{@link org.eclipse.iota.model.BinaryOperation#getLeft <em>Left</em>}' containment reference.
	 * @param value the new value of the '<em>Left</em>' containment reference.
	 * @see #getLeft()
	 * @generated
	 */
	public void setLeft(Expression newLeft) {
		if (newLeft != left) {
			NotificationChain msgs = null;
			if (left != null)
				msgs = ((InternalEObject)left).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - IotaPackage.BINARY_OPERATION__LEFT, null, msgs);
			if (newLeft != null)
				msgs = ((InternalEObject)newLeft).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - IotaPackage.BINARY_OPERATION__LEFT, null, msgs);
			msgs = basicSetLeft(newLeft, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IotaPackage.BINARY_OPERATION__LEFT, newLeft, newLeft));
	}

	/**
	 * Returns the value of the '<em><b>Right</b></em>' containment reference.
	 * @return the value of the '<em>Right</em>' containment reference.
	 * @see #setRight(Expression)
	 * @see org.eclipse.iota.IotaPackage#getBinaryOperation_Right()
	 * @model containment="true"
	 * @generated
	 */
	public Expression getRight() {
		return right;
	}

	/**
	 * @generated
	 */
	public NotificationChain basicSetRight(Expression newRight, NotificationChain msgs) {
		Expression oldRight = right;
		right = newRight;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, IotaPackage.BINARY_OPERATION__RIGHT, oldRight, newRight);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * Sets the value of the '{@link org.eclipse.iota.model.BinaryOperation#getRight <em>Right</em>}' containment reference.
	 * @param value the new value of the '<em>Right</em>' containment reference.
	 * @see #getRight()
	 * @generated
	 */
	public void setRight(Expression newRight) {
		if (newRight != right) {
			NotificationChain msgs = null;
			if (right != null)
				msgs = ((InternalEObject)right).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - IotaPackage.BINARY_OPERATION__RIGHT, null, msgs);
			if (newRight != null)
				msgs = ((InternalEObject)newRight).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - IotaPackage.BINARY_OPERATION__RIGHT, null, msgs);
			msgs = basicSetRight(newRight, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IotaPackage.BINARY_OPERATION__RIGHT, newRight, newRight));
	}

	/**
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case IotaPackage.BINARY_OPERATION__LEFT:
				return basicSetLeft(null, msgs);
			case IotaPackage.BINARY_OPERATION__RIGHT:
				return basicSetRight(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case IotaPackage.BINARY_OPERATION__EQUATION:
				if (resolve) return getEquation();
				return basicGetEquation();
			case IotaPackage.BINARY_OPERATION__LEFT:
				return getLeft();
			case IotaPackage.BINARY_OPERATION__RIGHT:
				return getRight();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case IotaPackage.BINARY_OPERATION__LEFT:
				setLeft((Expression)newValue);
				return;
			case IotaPackage.BINARY_OPERATION__RIGHT:
				setRight((Expression)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case IotaPackage.BINARY_OPERATION__LEFT:
				setLeft((Expression)null);
				return;
			case IotaPackage.BINARY_OPERATION__RIGHT:
				setRight((Expression)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case IotaPackage.BINARY_OPERATION__EQUATION:
				return basicGetEquation() != null;
			case IotaPackage.BINARY_OPERATION__LEFT:
				return left != null;
			case IotaPackage.BINARY_OPERATION__RIGHT:
				return right != null;
		}
		return super.eIsSet(featureID);
	}

}
